package cn.wolfcode.web.controller.cus;

import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import cn.wolfcode.common.enums.BusinessType;

import cn.wolfcode.common.utils.poi.ExcelUtil;
import cn.wolfcode.cus.domain.CusProfiles;
import cn.wolfcode.cus.service.ICusProfilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户档案Controller
 * 
 * @author zhangyf
 * @date 2023-04-21
 */
@RestController
@RequestMapping("/cus/profiles")
public class CusProfilesController extends BaseController
{
    @Autowired
    private ICusProfilesService cusProfilesService;

    /**
     * 查询客户档案列表
     */
    @PreAuthorize("@ss.hasPermi('cus:profiles:list')")
    @GetMapping("/list")
    public TableDataInfo list(CusProfiles cusProfiles)
    {
        startPage();
        List<CusProfiles> list = cusProfilesService.selectCusProfilesList(cusProfiles);
        return getDataTable(list);
    }

    /**
     * 导出客户档案列表
     */
    @PreAuthorize("@ss.hasPermi('cus:profiles:export')")
    @Log(title = "客户档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CusProfiles cusProfiles)
    {
        List<CusProfiles> list = cusProfilesService.selectCusProfilesList(cusProfiles);
        ExcelUtil<CusProfiles> util = new ExcelUtil<CusProfiles>(CusProfiles.class);
        util.exportExcel(response, list, "客户档案数据");
    }

    /**
     * 获取客户档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('cus:profiles:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cusProfilesService.selectCusProfilesById(id));
    }

    /**
     * 新增客户档案
     */
    @PreAuthorize("@ss.hasPermi('cus:profiles:add')")
    @Log(title = "客户档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CusProfiles cusProfiles)
    {
        return toAjax(cusProfilesService.insertCusProfiles(cusProfiles));
    }

    /**
     * 修改客户档案
     */
    @PreAuthorize("@ss.hasPermi('cus:profiles:edit')")
    @Log(title = "客户档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CusProfiles cusProfiles)
    {
        return toAjax(cusProfilesService.updateCusProfiles(cusProfiles));
    }

    /**
     * 删除客户档案
     */
    @PreAuthorize("@ss.hasPermi('cus:profiles:remove')")
    @Log(title = "客户档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cusProfilesService.deleteCusProfilesByIds(ids));
    }
}
